Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support filtering snapshots by IDs #299

Merged
merged 1 commit into from
Apr 20, 2020

Conversation

timoreimann
Copy link
Contributor

@timoreimann timoreimann commented Apr 17, 2020

Our implementation of ListSnapshots currently returns all snapshots. The request parameter also provides fields to filter by snapshot ID and source volume ID, which we have been ignoring so far.

Based on discussions with SIG Storage, it became clear that CSI
drivers are expected to process present IDs in the ListSnapshots call appropriately. While the spec marks them as OPTIONAL, it turned out that the optionality refers to the CO, not the SP. (A request for clarification has been filed.) As soon as any of IDs are provided, drivers are expected to take them into account. In fact, csi-snapshotter always passes a snapshot ID in and only ever takes the first snapshot item from the list of snapshots returned, which means that our current implementation is buggy for cases where the account holds more than one snapshot or the desired snapshot doesn't happen to be on top of the list of returned snapshots (at least on Kubernetes; other COs could potentially behave differently).

This change fixes the issue by retrieving the snapshot by direct lookup if a snapshot ID is given.

If a source volume ID is given, we do additional filtering by only returning the snapshots that were sourced by the same volume.

The existing csi-sanity tests did not catch this bug. A PR to that project was submitted to close the gap. I tested it locally and verified that the test now works. Once it is merged, we should upgrade our version of the test package.

Our implementation of ListSnapshots currently returns all snapshots. The
request parameter also provides fields to filter by snapshot ID and
source volume ID, which we have been ignoring so far.

Based on discussions with SIG Storage [1], it became clear that CSI
drivers are expected to process present IDs in the ListSnapshots call
appropriately. While the spec marks them as OPTIONAL, it turned out that
the optionality refers to the CO, not the SP. (A request for
clarification has been filed in [2].) As soon as any of IDs are
provided, drivers are expected to take them into account.  In fact,
csi-snapshotter always passes a snapshot ID in and only ever takes the
first snapshot item from the list of snapshots returned, which means
that our current implementation is buggy for cases where the account
holds more than one snapshot (at least on Kubernetes; other COs could
potentially behave differently).

This change fixes the issue by retrieving the snapshot by direct lookup
if a snapshot ID is given.

If a source volume ID is given, we do additional filtering by only
returning the snapshots that were sourced by the same volume.

The existing csi-sanity tests did not catch this bug. A PR to that
project was submitted [3] to close the gap. Once it is merged, we should
upgrade our version of the test package.

[1]: https://kubernetes.slack.com/archives/C8EJ01Z46/p1587038433091900
[2]: container-storage-interface/spec#426
[3]: kubernetes-csi/csi-test#259
@timoreimann timoreimann requested review from adamwg and nicktate April 17, 2020 10:59

if resp.Links == nil || resp.Links.IsLastPage() {
break
if nextToken != 0 && req.MaxEntries != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't you have an offset coupled with the page count in this instance?

}
var snapshots []godo.Snapshot
for {
snaps, resp, err := d.snapshots.ListVolume(ctx, listOpts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused with this pagination section below. It seems like we paginate through every entry from the start, ignoring the offset of NextToken that is returned. Can we just determine the "pageNumber" in DO pagination terms as a calculation of the pageCount and the offset?

Copy link
Contributor Author

@timoreimann timoreimann Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right, the logic looks off. I did not pay much attention to it because existing code was just moved into an else branch but was otherwise not modified. So I believe the pagination had been suboptimal before. Great catch. 👍

If you don't mind then I'd like to address this issue in a separate PR. FWIW, the flawed pagination should not have impacted users much since csi-snapshotter always passes in a snapshot ID in the ListSnapshots request, and our handling of that parameter is only fixed by this PR. Being good CSI citizens, however, we should still fix the pagination for the case that ListSnapshots is ever consumed exhaustively either in the future or by other COs (container orchestrators) possibly today already.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 That works for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix submitted in #300.

@timoreimann timoreimann merged commit 0d8f2b5 into master Apr 20, 2020
@timoreimann timoreimann deleted the support-filtering-snapshots-by-ids branch April 20, 2020 07:02
timoreimann pushed a commit that referenced this pull request Apr 22, 2020
This change updates csi-test to digitalocean/csi-test@master. We use our
own fork which sits on top of upstream master and comes with the
following customizations:

- The 'should fail when the volume is missing' test is disabled because
  it does not work for us right now. See [1] for details and our effort
  to improve upstream.
- It adds yet unreleased tests for our change in [2] (specifically,
  [3]).

Going forward, we plan to return to using the upstream, released test
package.

[1]: kubernetes-csi/csi-test#258
[2]: #299
[3]: kubernetes-csi/csi-test@b91f254
timoreimann pushed a commit that referenced this pull request Apr 23, 2020
This change updates csi-test to digitalocean/csi-test@master. We use our
own fork which sits on top of upstream master and comes with the
following customizations:

- The 'should fail when the volume is missing' test is disabled because
  it does not work for us right now. See [1] for details and our effort
  to improve upstream.
- It adds yet unreleased tests for our change in [2] (specifically,
  [3]).

Going forward, we plan to return to using the upstream, released test
package.

[1]: kubernetes-csi/csi-test#258
[2]: #299
[3]: kubernetes-csi/csi-test@b91f254
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants